<template>
  <div class="admin-index">
    <div class="welcome-panel bgwhite">
      <div class="welcom-info2">
        <div class="clearfix">
          <div class="info-left">
            <div class="title">您好！{{ user.name }}</div>
            <div class="txt">欢迎使用油气管道动火作业综合监控平台！</div>
            <div class="enter-info">
              <div class="media">
                <div class="media-left">
                  <el-avatar :size="60" :src="enterprise.picture | imgPath">
                    <img src="~@/assets/img/default.png" style="width: 60px" />
                  </el-avatar>
                </div>
                <div class="media-body">
                  <div class="display-flex">
                    <div class="box3 tit text-ellipsis">
                      {{ enterprise.name }}
                    </div>
                    <div class="box1">
                      <i v-permission="['superSysOpsAdmin', 'entAdmin']" class="el-icon-edit-outline"
                      
                      @click="editHandle" /> 
                    </div>
                  </div>
                  <div class="adres text-ellipsis">
                    <i class="icon-weizhi iconfont" />
                    {{ enterprise.provinceName }}{{ enterprise.cityName
                    }}{{ enterprise.countyName }}{{ enterprise.streetName
                    }}{{ enterprise.address }}
                  </div>
                </div>
              </div>
            </div>
            <div class="btn-info">
              <el-button type="primary" @click.native="viewHandle">进入 大屏</el-button>
            </div>
          </div>
          <div class="info-right">
            <img src="@/assets/img/enterbg.png" />
          </div>
        </div>
      </div>
    </div>
    <!-- 界面 -->
    <el-dialog ref="drawer" title="编辑" :visible.sync="drawer" close-on-press-escape destroy-on-close>
      <div v-if="drawer" class="draw-body">
        <el-form ref="ruleForm" :model="object" :rules="rules" :validate-on-rule-change="false" label-width="120px"
          label-suffix=":">
          <el-form-item label="企业名称" prop="name">
            <el-input v-model="object.name" maxlength="30" show-word-limit />
          </el-form-item>
          <el-form-item label="企业logo" prop="picture">
            <wise-file v-model="object.picture" upload-type="image" />
          </el-form-item>
          <el-form-item label="企业宣传图" prop="publicityPicture">
            <wise-file v-model="object.publicityPicture" :limit="5" upload-type="image" />
          </el-form-item>
          <!--          <el-form-item label="企业管理员" prop="entAdminUserId">-->
          <!--            <el-select v-model="object.entAdminUserId" placeholder="请选择">-->
          <!--              <el-option-->
          <!--                v-for="(item, index) in UserList"-->
          <!--                :key="index"-->
          <!--                :label="item.username"-->
          <!--                :value="item.userId"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item label="组织机构代码" prop="organization">
            <el-input v-model="object.organization" maxlength="30" />
          </el-form-item>
          <el-form-item label="联系邮箱" prop="phone">
            <el-input v-model="object.phone" maxlength="30" />
          </el-form-item>
          <el-form-item label="单位电话" prop="eamil">
            <el-input v-model="object.eamil" maxlength="11" />
          </el-form-item>
          <el-form-item label="法人代表" prop="legalPerson">
            <el-input v-model="object.legalPerson" />
          </el-form-item>
          <el-form-item label="单位传真" prop="fax">
            <el-input v-model="object.fax" maxlength="11" />
          </el-form-item>
          <el-form-item label="邮政编码" prop="postalCode">
            <el-input v-model="object.postalCode" />
          </el-form-item>
          <el-form-item label="成立时间" prop="established">
            <wise-date v-model="object.established" />
          </el-form-item>
          <el-form-item label="地址" prop="area">
            <wise-region v-model="object.area" :obj-keys="[
                {
                  field: 'provinceCode',
                  key: 'province',
                  value: 'key',
                },
                {
                  field: 'provinceName',
                  key: 'province',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'cityCode',
                  key: 'city',
                  value: 'key',
                },
                {
                  field: 'cityName',
                  key: 'city',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'countyCode',
                  key: 'area',
                  value: 'key',
                },
                {
                  field: 'countyName',
                  key: 'area',
                  value: 'value',
                  tableShow: true,
                },
                {
                  field: 'streetCode',
                  key: 'town',
                  value: 'key',
                },
                {
                  field: 'streetName',
                  key: 'town',
                  value: 'value',
                  tableShow: true,
                },
              ]" @on-value="setValue" />
          </el-form-item>
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="object.address" maxlength="300" show-word-limit />
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="object.remark" type="textarea" placeholder="请输入备注" maxlength="1000" show-word-limit />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import permission from "../../directive/permission/index.js"; // 权限判断指令
  import WiseRegion from "@/components/Crud/components/wiseRegion";
  import WiseDate from "@/components/Crud/components/wiseDate";
  import WiseFile from "@/components/Crud/components/wiseFile";
  import {
    postHandle
  } from "@/api";
  export default {
    name: "DashboardAdmin",
    components: {
      WiseFile,
      WiseDate,
      WiseRegion
    },

    data() {
      return {
        drawer: false,
        img: "",
        type: "",
        object: {
          name: null,
          picture: null,
          publicityPicture: null,
          entAdminUserId: null,
          entAdmin: {},
          organization: null,
          scale: null,
          eamil: null,
          phone: null,
          legalPerson: null,
          provinceCode: null,
          provinceName: null,
          cityCode: null,
          cityName: null,
          countyCode: null,
          countyName: null,
          streetCode: null,
          streetName: null,
          address: null,
          fax: null,
          postalCode: null,
          established: null,
          remark: null,
        },
        rules: {
          name: [{
            required: true,
            message: "请输入活动名称",
            trigger: "blur"
          }],
          picture: [{
            required: true,
            message: "请上传企业logo",
            trigger: "blur"
          }, ],
          organization: [{
            required: true,
            message: "请输入组织机构代码",
            trigger: "blur"
          }, ],
          eamil: [{
            required: true,
            message: "请输入联系邮箱",
            trigger: "blur"
          }],
          phone: [{
            required: true,
            message: "请输入单位电话",
            trigger: "blur"
          }],
          legalPerson: [{
            required: true,
            message: "请输入法人代表",
            trigger: "blur"
          }, ],
        },
        UserList: [],
      };
    },

    computed: {
      user() {
        return this.$store.state.user;
      },
      enterprise() {
        return this.$store.state.enterprise.obj;
      },
    },

    directives: {
      permission
    },

    created() {
      this.getUserList();
      
    },

    methods: {
      viewHandle() {
        this.$router.push({
          name: "screen"
        });
        // if (this.enterprise.bigScreenType == 1) {
        //   window.open(
        //     "/enterprise/screen?id=" +
        //       this.enterprise.spaceId +
        //       "&img=" +
        //       this.enterprise.bigScreenStr
        //   );
        // } else {
        //   window.open(this.enterprise.bigScreenStr);
        // }
      },
      editHandle() {
        for (let key in this.enterprise) {
          this.object[key] = this.enterprise[key];
        }
        this.object.area = {
          province: {
            key: this.object.provinceCode,
            value: this.object.provinceName,
          },
          city: {
            key: this.object.cityCode,
            value: this.object.cityName,
          },
          area: {
            key: this.object.countyCode,
            value: this.object.countyName,
          },
          town: {
            key: this.object.streetCode,
            value: this.object.streetName,
          },
        };
        this.drawer = true;
        // this.object = this.enterprise
      },
      submitForm(ruleForm) {
        this.$refs[ruleForm].validate((valid) => {
          if (valid) {
            postHandle(
                `/api/v1/welder-sbtx-second/enterprise-comb/update/${this.object.id}`, {
                  obj: this.object
                }
              )
              .then((response) => {
                this.$message("操作成功");
                this.drawer = false;
              })
              .catch((error) => {
                const data = error.response.data;
                for (const key in data) {
                  this.$message.error(this.$t(key) + this.$t(data[key]));
                }
              });
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      resetForm(ruleForm) {
        (this.object = {
          name: null,
          picture: null,
          publicityPicture: null,
          entAdminUserId: null,
          entAdmin: {},
          organization: null,
          scale: null,
          eamil: null,
          phone: null,
          legalPerson: null,
          provinceCode: null,
          provinceName: null,
          cityCode: null,
          cityName: null,
          countyCode: null,
          countyName: null,
          streetCode: null,
          streetName: null,
          address: null,
          fax: null,
          postalCode: null,
          established: null,
          remark: null,
        }),
        this.$refs[ruleForm].resetFields();
      },
      setValue(objVal) {
        if (objVal && objVal.length > 0) {
          objVal.forEach((item) => {
            this.$set(this.object, item.field, item.value);
          });
        }
      },
      getUserList() {
        const req = {
          d: {},
          obj: {},
        };
        postHandle(
          "/api/v1/welder-uac-second/user-information-comb/get-user-info-filter-valid-list",
          req
        ).then((response) => {
          this.UserList = response.result;
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .clearfix:after,
  .clearfix:before,
  .media:after,
  .media:before {
    display: table;
    content: " ";
  }

  .clearfix:after,
  .media:after {
    clear: both;
  }

  .admin-index .panel {
    background: #f5f5f5;
  }

  .admin-index .panel .panel-body {
    padding: 50px;
  }

  .admin-index .panel .panel-body .media .media-left {
    float: left;
  }

  .admin-index .panel .panel-body .media .media-body {
    overflow: hidden;
    padding-left: 30px;
  }

  .admin-index .panel .panel-body .media .media-body .name {
    color: #8f2d07;
    font-size: 38px;
    margin-top: 20px;
    margin-bottom: 10px;
  }

  .admin-index .panel .panel-body .media .media-body .txt {
    font-size: 20px;
    line-height: 20px;
    color: #000;
  }

  .user-bottom {
    width: 100%;
    height: 643px;
    background-color: #fff;
    position: relative;
  }

  .user-bottom .icon-part {
    width: 320px;
    height: 225px;
    margin: 0 auto;
    position: relative;
    top: 159px;
  }

  .user-bottom .icon-part .tip-more {
    height: 40px;
    font-size: 28px;
    font-weight: 400;
    color: #bbbbbb;
    line-height: 40px;
    text-align: center;
    margin-top: 43px;
  }

  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
      border-color: rgba(0, 0, 0, 0.05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #40c9c6;
        }

        .icon-message {
          background: #36a3f7;
        }

        .icon-money {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3;
        }
      }

      .icon-people {
        color: #40c9c6;
      }

      .icon-message {
        color: #36a3f7;
      }

      .icon-money {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3;
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width: 550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }

  .home-block {
    .home-info1 {
      padding: 30px 40px;
      margin-bottom: 25px;
      background: #fff;

      .media {
        .media-left {
          .el-icon-user-solid {
            font-size: 40px;
            line-height: 70px;
          }
        }

        .media-body {
          padding-top: 10px;

          .title {
            font-size: 20px;
            font-weight: 500;
            color: rgba(0, 0, 0, 0.85);
            line-height: 28px;
            margin-bottom: 5px;
          }

          .txt {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.45);
            line-height: 22px;
          }
        }
      }

      .list-info {
        li {
          width: 20%;
          float: left;
          text-align: center;
          border-right: 1px solid #e9e9e9;
          cursor: pointer;

          &:last-child {
            border-right: 0;
          }

          .txt {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.45);
            line-height: 22px;
          }

          .num {
            font-size: 30px;
            font-family: HelveticaNeue;
            color: rgba(0, 0, 0, 0.85);
            line-height: 38px;
          }
        }
      }
    }

    .home-info2 {
      padding: 30px 40px;
      background: #fff;

      .audit-list {
        .item {
          padding: 20px;
          border: 1px solid #eee;
          margin-bottom: 20px;

          .title {
            font-size: 16px;
            font-weight: 500;
            color: rgba(85, 85, 85, 1);
            line-height: 20px;
            margin-bottom: 10px;
            width: 360px;
          }

          .depart {
            font-size: 14px;
            font-weight: 500;
            color: rgba(85, 85, 85, 1);
            line-height: 20px;
            margin-bottom: 10px;

            .name {
              padding-right: 10px;
            }
          }

          .txt {
            font-size: 12px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.25);
            line-height: 20px;
          }

          .time {
            font-size: 12px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.25);
            line-height: 20px;
            margin-top: 40px;
          }

          &:hover {
            background: rgba(216, 216, 216, 0.13);
            border: 1px solid #979797;
          }
        }
      }
    }
  }
</style>